<template>
  <div class="head-title" ref="video">
    <van-nav-bar left-text="返回" :title="title" fixed left-arrow @click-left="onClickLeft" />

    <van-cell-group class="message">
      <div class="content">
        <van-row>
          <van-col span="4" class="name">
            <span>
              <img :src="head_image" class="commitImage" />
            </span>
          </van-col>
          <van-col span="18" offset="2" class="conmit">
            <van-row>
              <van-col span="12">
                <span class="autr">{{createUserName}}</span>
              </van-col>
              <!-- <van-col span="2" offset="7">
                <span class="LinkNum">{{item.Num}}</span>
              </van-col>
              <van-col span="3">
                <span class="autrLiNK" @click="AddLike(index,item)">点赞</span>
              </van-col> -->
            </van-row>

            <span class="conmitNote">{{Dcontent}}</span>
            <van-row class="resActive">
              <van-col span="12">
                <span class="restime">{{time}}</span>
              </van-col>
              <!-- <van-col span="8">
                <span class="reqsDis" @click="reqsDis(index)">回复</span>
              </van-col> -->
              <!-- <van-col span="8">
                <span class="resCommit resCommitDel" @click="DeleteDiscuss(index)">x</span>
              </van-col> -->
            </van-row>
          </van-col>
        </van-row>
      </div>
    </van-cell-group>

   <van-divider :style="{ color: '#1989fa', borderColor: '#1989fa', padding: '0 16px' }">
    全部评论
   </van-divider>

    <van-cell-group class="message">
      <div v-for="(item,index) in this.messageList" :key="index" class="content">
        <van-row>
          <van-col span="4" class="name">
            <span>
              <!-- :src="item.playbill_url" -->
              <img :src="item.head_image" class="commitImage" />
            </span>
          </van-col>
          <van-col span="18" offset="2" class="conmit">
            <van-row>
              <van-col span="12">
                <span class="autr">{{item.createUserName}}</span>
              </van-col>
              <van-col span="2" offset="7">
                <span class="LinkNum">{{item.Num}}</span>
              </van-col>
              <van-col span="3">
                <span class="autrLiNK" @click="AddLike(index,item)">点赞</span>
              </van-col>
            </van-row>
            <van-row class="ComeNote">
            <span class="conmitNote to_UserID " v-show="item.toUserName != null && item.to_UserID != null">{{ '@' + item.toUserName  + "&nbsp;&nbsp;" }}</span>
            <span class="conmitNote" >{{ item.content}}</span>
            </van-row>
            <van-row class="resActive">
              <van-col span="12">
                <span class="restime">{{item.time}}</span>
              </van-col>
              <van-col span="6">
                <span class="reqsDis" @click="reqsDis(index)">回复</span>
              </van-col>
              <van-col span="6">
                <span class="resCommit resCommitDel"  v-show=" item.createUserID  == item.UserID " @click="DeleteDiscuss(index)">x</span>
              </van-col>
            </van-row>
          </van-col>
        </van-row>
      </div>
    </van-cell-group>

    <!-- 输入评论 -->
    <van-cell-group class="comment">
      <van-field
        v-model="content"
        rows="1"
        @focus="ss()"
        autosize
        :disabled ='contentDis'
        :label="this.toUserName"
        type="textarea"
        placeholder="请输入留言"
      >
        <template #button>
          <van-button size="small" type="primary" :disabled ='btnDisable'  @click="AddDiscuss()">保存</van-button>
        </template>
      </van-field>
    </van-cell-group>
  </div>
</template>

<script>

import { Toast } from "vant";
import { ShareSheet } from "vant";

export default {
  data() {
    return {
      head_image:'',
      createUserName:'',
      Dcontent:'',
      time:'',
      note: "",
      showShare: false,
      message: "", //留言
      content: null, //评论
      messageList: [], //评论列表
      FileId: "",
      LinkNum: 0,
      disabledBnt: true,
      to_UserID:'',
      contentDis:true,
      btnDisable:true,
      toUserName:''
    };
  },
  methods: {

    //返回数据
    
    onClickLeft() {
      this.$router.push({
        path: "/overWorkNote",
        query: {
          ID: this.$route.query.ID,
          id: this.$route.query.id
        }
      });
    },

    //修改数据
    reqsDis(index){
        console.log(this.messageList[index].createUserName);
        this.toUserName = '我' + '@' + this.messageList[index].createUserName;
        // this.content = '@' + this.messageList[index].createUserName + '@';
        this.to_UserID = this.messageList[index].createUserID;
        this.contentDis = false,
        this.btnDisable = false
    },

    //增加评论
    AddDiscuss() {
      console.log(this.content);
      // let ss = this.content.split('@');
      // console.log(ss[ss.length - 1]);
      const PWD = JSON.parse(sessionStorage.getItem("PWD"));
      
      if(!PWD){
         Toast('请先登录');
         //this.$router.push
         this.$router.push({
              path: "/login",
         });
         return false;
      }
      
      let FileID = this.$route.query.ID;
      const reqID = this.$route.query.reqID;
      this.$axios({
        method: "post",
        url: "/api/User/AddDiscuss",
        headers: { sessionKey: PWD.sessionKey, authorization: PWD.token },
        data: {
          fileID: FileID, //文件ID
          to_UserID:  this.to_UserID, //对谁说
          to_DiscussID: reqID, //对某个评论ID进行回复
          content: this.content //内容
        }
      })
        .then(res => {
          if (res.data.code === 0) {
            console.log(res.data.data);
            this.content = null;
            //输出所有值
            this.GetDiscussList();
            this.contentDis = true;
            this.btnDisable = true;
            
          }
          if (res.data.code == 1) {
            this.$toast({
              duration: 800,
              message: res.data.message
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    /*
    删除评论
    */
    DeleteDiscuss(index) {
      console.log(this.messageList[index].id);
      const PWD = JSON.parse(sessionStorage.getItem("PWD"));
      this.$axios({
        method: "post",
        url: "/api/User/DeleteDiscuss",
        headers: { sessionKey: PWD.sessionKey, authorization: PWD.token },
        data: {
          id: this.messageList[index].id
        }
      })
        .then(res => {
          if (res.data.code === 0) {
            console.log(res.data.data);
            this.$toast({
              duration: 800,
              message: "删除评论"
            });
            //删除成功以后再获取一下数据11111
            this.GetDiscussList();
          }
          if (res.data.code == 1) {
            this.$toast({
              duration: 800,
              message: res.data.message
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    /*
    //获取某个某个文件下【的某个评论】的所有回复（discussId > 0 为评论下的所有回复）
    */
    GetDiscussList() {
      //获取id
      let Id = this.$route.query.ID;
      const PWD = JSON.parse(sessionStorage.getItem("PWD"));
      const reqID = this.$route.query.reqID;

      this.$axios({
        method: "post",
        url: "/api/User/QueryPageListDiscussList ",
        headers: { sessionKey: PWD.sessionKey, authorization: PWD.token },
        data: {
          fileID: Id, //文件ID
          discussID: reqID, //评论ID
          pageIndex: 1, //获取或设置 当前页码。
          pageSize: 50, //获取或设置 每页显示数据量。
          recordCount: 0 //获取或设置 所有符合查询条件的总数据量。
        }
      })
        .then(res => {
          if (res.data.code === 0) {
            for (let i = 0; i < res.data.data.resultList.length; i++) {
              console.log(res.data.data.resultList[i]);
              res.data.data.resultList[i].time =  res.data.data.resultList[i].createTime;
              res.data.data.resultList[i].Num = 0 ;
              res.data.data.resultList[i].UserID = JSON.parse(sessionStorage.getItem('PWD')).id ;
            }
            this.messageList = res.data.data.resultList;
          }
          if (res.data.code == 1) {
            this.$toast({
              duration: 800,
              message: res.data.message
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    }

  },
  
  //页面初始化钩子函数 created
  created() {
    //获取详情数据
    // this.GetDiscussList();
    this.$emit("header", false);
    this.$emit("footer", false);
    this.title = this.$route.query.title;
    //获取该文件下所有评论
    this.GetDiscussList();
  },

  //页面初始化钩子函数 mounted
  mounted() {
    
    let data = JSON.parse(sessionStorage.getItem('reqsDis'));

    this.head_image = data.head_image,
    this.createUserName = data.createUserName ,
    this.Dcontent = data.content ,
    this.time =  data.createTime
  }
};
</script>

<style lang="less" scoped>
.vant {
  height: 20px;
  width: 20px;
}

.gorouterBtn {
  letter-spacing: 10px;
  font-size: 14px;
}

.van-row {
  line-height: 35px;
}
.Nodata {
  text-align: center;
  margin-top: 150px;
}
.iconlogo {
  width: 100%;
}
.textR {
  font-size: 12px;
  display: block;
  padding-left: 20px;
}
.videoBtn {
  margin-top: 80px;
  margin-left: 80px;
}
.NoteD {
  background-color: #fff;
  margin-top: 10px;
}
.NoteD > span {
  display: block;
  font-size: 12px;
  margin-left: 10px;
  margin-right: 10px;
  //  line-height: 10px;;
  line-height: 30px;
}
.ShowVideo {
  background-color: #fff;
  span {
    border-bottom: 1px solid #eee;
    // text-align: center;
  }
}
.textNote {
  line-height: 30px;
}
.textNoHeader {
  background-color: #21a675;
  padding: 0;
  margin: 0;
  padding-left: 10px;
  color: #fff;
}

///

.video {
  width: 40px;
  height: 40px;
  background-color: #99cc99;
  line-height: 40px;
  text-align: center;
  display: inline-block;
  margin: 5px;
  color: #fff;
  font-size: 12px;
  // overflow: scroll;
}
// .VideoShow{
//    overflow: scroll;
// }
.Videolist {
  // padding-left: 10px;
  margin-top: 10px;
  .ShowVideo {
    padding-left: 10px;
  }
}
.videoArry {
  float: right;
}

.lineText {
  height: 36px;
  background-color: #fff;
  border-bottom: 1px solid #eee;
  // margin-top: 10px;
  // margin-bottom: 10px;
}

.lineText span {
  line-height: 30px;
  font-size: 14px;
  // background-color: #fff;
}

.lineText_Right {
  // float:right;
  text-align: end;
  padding-right: 20px;
  font-size: 12px;
  color: cadetblue;
  margin-top: 5px;
}
.lineText01 {
  background-color: #fff;
  margin-top: 10px;
  .lineText_left {
    padding-left: 10px;
    .TextL {
      font-size: 12px;
      // line-height: 12px;
    }
  }
}

.nav_item {
  background: #fff;
  width: 100%;
  border-bottom: 1px solid #eee;
  text-align: center;
}
.iconame {
  // top: -10px;
  z-index: 9999;
  position: relative;
  // background-color: #000;
  height: 20px;
  display: block;
  font-size: 12px;
  line-height: 20px;
  // font-family: "Courier New", Courier, monospace;
  color: #000;
  text-align: left;
  padding-left: 10px;
  margin-bottom: 5px;
  // opacity: 0.5;
}
//
.Icon_Fengxian {
  width: 200px;
}
//
.iconlogo {
  height: 150px;
}
//评论
.comment {
  position: fixed;
  left: auto;
  right: auto;
  bottom: 0;
  width: 100%;
  z-index: 2000;
}
.message {
  margin-top: 10px;
//   margin-bottom: 60px;
  .name {
    // background-color: red;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-left: 15px;
    .commitImage {
      width: 35px;
      height: 35px;
      margin-top: 10px;
      border-radius: 50%;
      border: 1px solid #eeeeee;
      background-color: #ffcc99;
      // margin: 10px;
    }
  }
  .conmit {
    // background-color: blue;
    margin-left: 20px;
    border-radius: 5px;
    span {
      display: block;
      font-size: 12px;
      line-height: 20px;
    }
    .autr {
      color: #99ccff;
      padding-top: 10px;
    }
    .autrLiNK {
      text-align: end;
      padding-right: 10px;
      color: #99ccff;
      padding-top: 10px;
    }
    .LinkNum {
      text-align: center;
      margin-right: 10px;
      color: #ffffff;
      margin-top: 10px;
      width: 20px;
      height: 20px;
      border-radius: 50%;
      background-color: #ff9966;
    }
    .resCommit {
      float: right;
      // margin-right: 10px;
    }
    .resCommitDel {
      margin-left: 20px;
    }
  }
}
.Icon {
  width: 25px;
}
.savebtn {
  margin-bottom: 10px;
}

.content {
  border-bottom: 1px solid #eee;
  .ComeNote{
    display: flex;
    .to_UserID{
      color: #99ccff;
      font-size: 12px;
    }
    .conmitNote {
      margin-top: 5px;
      margin-bottom: 5px;
    }
  }
  
  .resActive {
    margin-bottom: 5px;
    line-height: 15px;
    .reqsDis {
      background-color: #eee;
      font-size: 10px;
      padding: 2px 10px;
      border-radius: 10px;
      margin-top: 5px;
      width: 30px;
      text-align: center;
    }
    .restime {
      margin-top: 10px;
      font-size: 10px;
    }
    .resCommitDel {
      margin-top: 5px;
      padding: 1px 20px;
      border: 1px solid #eee;
      border-radius: 10px;
    }
  }
}
</style>

